package com.easy.blog.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.easy.blog.model.Article;
import com.easy.blog.service.ArticleService;
import com.easy.blog.util.PageParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/article")
public class ArticleController {

    @Autowired
    private ArticleService articleService;

    @GetMapping
    public ResponseEntity<IPage<Article>> page(PageParam<Article> page) {
        articleService.page(page, null);
        return ResponseEntity.ok(articleService.page(page, null));
    }

    @GetMapping("/{id}")
    public ResponseEntity<Article> info(@PathVariable("id") Long id) {
        Article info = articleService.getById(id);
        return ResponseEntity.ok(info);
    }
}
